/*
 * Copyright (c) Huawei Technologies Co.,Ltd. 2023. All rights reserved.
 */
package org.opengauss.intercept;

import org.apache.ibatis.cache.CacheKey;
import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Plugin;
import org.apache.ibatis.plugin.Signature;
import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds;

/**
 * Title: the StatementIntercept class.
 * <p>
 * Description:
 *
 * @author justbk
 * @version [Tools 0.0.1, 2023/7/24]
 * @since 2023/7/24
 */
@Intercepts(value = {
//        @Signature(type= Executor.class, method = "update", args = {MappedStatement.class, Object.class}),
        @Signature(type= Executor.class, method = "query", args = {MappedStatement.class, Object.class,
                RowBounds.class, ResultHandler.class}),
        @Signature(type= Executor.class, method = "query", args = {MappedStatement.class, Object.class,
                RowBounds.class, ResultHandler.class, CacheKey.class, BoundSql.class})
})
public class SelfIntercept implements Interceptor {
    @Override
    public Object intercept(final Invocation invocation) throws Throwable {
//        StatementHandler.class;
//        ResultHandler.class;
//        TypeHandler.class
        return DataRecordFactory.getExectorRecord().doRecord(invocation);
    }
    
    @Override
    public Object plugin(final Object target) {
        return Plugin.wrap(target, this);
    }
}
